package org.dong.Tool;

import org.dong.Pojo.HttpRequest;
import org.dong.Pojo.HttpResponse;

import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.net.Socket;

public class WebServerThread extends Thread {

    private Socket socket;
    private OutputStream os;
    private InputStream is;
    public WebServerThread(Socket socket){
        try {
             socket = socket;
            //创建输出流
             os = socket.getOutputStream();
            //创建输入流
             is = socket.getInputStream();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void run() {
        String msg = "OK";

        while (true) {


            HttpRequest request = new HttpRequest(is);
            //判断请求方式
            if(request.getRequestMethod().equals("POST")){
                try {
                    new ControllerReflex(request,os);
                } catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException | ClassNotFoundException | IOException e) {
                    e.printStackTrace();
                }
            }else{
                HttpResponse response = new HttpResponse(os,request.getUrl(),msg);

            }


        }


    }
}
